require(['./config'], () => {
    require(['server', 'template', 'nav', 'foot'], (server, template) => {
        class Gift {
            constructor() {
                this.init()
            }
            init() {
                $('.main .father-class .series').on('click', 'a', function() {
                    open('/html/category.html?' + $(this).parents('.father-class').attr('type-title') + '=' + $(this).attr('je-type'));
                })

                $.get(server.baseServerUrl + '/api/v1/goods/select.php', resp => {
                    let res = JSON.parse(resp).body.list
                    res = res.map(function(item) {
                        if (item.img.indexOf('@') != -1) {
                            item.img = item.img.slice(0, item.img.indexOf('@'))
                        }
                        return item
                    })
                    let resHT = res.filter((item) => item['series'] == 'HT');
                    let resCB = res.filter((item) => item['series'] == 'CB');
                    let resYJ = res.filter((item) => item['series'] == 'YJ');
                    let resF = res.filter((item) => item['series'] == 'F');

                    if (resHT.length > 4) {
                        resHT = resHT.slice(0, 4)
                    }
                    if (resCB.length > 4) {
                        resCB = resCB.slice(0, 4)
                    }
                    if (resYJ.length > 4) {
                        resYJ = resYJ.slice(0, 4)
                    }
                    if (resF.length > 4) {
                        resF = resF.slice(0, 4)
                    }
                    let str = template('seriesHT-list-template', {
                        list: resHT
                    })
                    $('#seriesHT-good-list').html(str)
                    $('#seriesCB-good-list').html(template('seriesCB-list-template', {
                        list: resCB
                    }))
                    $('#seriesYJ-good-list').html(template('seriesYJ-list-template', {
                        list: resYJ
                    }))
                    $('#seriesF-good-list').html(template('seriesF-list-template', {
                        list: resF
                    }))
                })
            }
        }
        new Gift()
    })
})